app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){
    console.log('------$scope.menuId1-----', $scope.menuId);
    console.log('------$scope.buttonArr1-----', $scope.buttonArr);

    $scope.bindBtn = function(event) {
        var datas = $scope.getSelectedRows();
        var t = this;
        switch(event){
            case 'event-to-addToManage':
            {
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                    return;
                }
                var loadIndex = layer.confirm('确定要将所选择的日志添加至管理?', {icon: 3}, function () {
                    //点击确定的回调
                    layer.close(loadIndex);
                    layer.load(2);

                    var ids = '';
                    for(var i=0;i<datas.length;i++){
                        if(ids==''){
                            ids = datas[i].id;
                        }else {
                            ids = ids+','+datas[i].id;
                        }
                    }

                    console.log('ids',ids);
                    $http.post('/api/inter/eKnowChatLog/chatLogAddManage', {}, {params: {ids: ids}})
                        .success(function (result) {
                            console.log('result',result);
                            if(result.code=='SUCCESS'){
                                layer.closeAll();
                                layer.msg("操作成功", {icon: 1});
                                location.reload();
                            }else {//失败
                                layer.closeAll();
                                layer.msg(result.msg, {icon: 2});
                            }
                        })
                        .error(function(result){
                            layer.closeAll();
                            layer.msg("操作失败，请稍后再试！", {icon: 2});
                        });

                    /*
                    $.ajax({
                        url: '/api/inter/eKnowChatLog/chatLogAddManage',
                        data: "list="+_list,
                        type: 'POST',
                        async: true,
                        timeout: 60000,
                        success: function (result) {
                            if(result.code=='SUCCESS'){
                                layer.closeAll();
                                layer.msg("操作成功", {icon: 1});
                                location.reload();
                            }else {//失败
                                layer.closeAll();
                                layer.msg("操作失败，请稍后再试！", {icon: 2});
                            }
                        },
                        error: function () {
                            layer.closeAll();
                            layer.msg("操作失败，请稍后再试！", {icon: 2});
                        }
                    });

                     */
                }, function () {return false;});//点击取消的回调
                break;
            }
        };
    }
}
